package com.molin.networkTest.socketTest.demo3;

import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;

public class ServerDemo {
    //    UDP接收数据：因为接收端不知道发送端什么时候停止发送，故采用死循环接收
    public static void main(String[] args) throws IOException {
        DatagramSocket socket=new DatagramSocket(8888);

        while (true) {
            byte[] bytes=new byte[1024];
            DatagramPacket dp=new DatagramPacket(bytes,bytes.length);
            socket.receive(dp);
            int length=dp.getLength();
            System.out.println(new String(bytes,0,length));
        }

    }
}
